#include "iostream"
#include "vector"
#include "algorithm"

using namespace std;

const int N = 100010;

typedef pair<int, int> PII;

int n;

vector<PII> segs;

void merge(vector<PII> &segs)
{
	vector<PII> res;
	
	sort(segs.begin(), segs.end());
	
	int star = -2e9, end = -2e9;
	for(auto seg : segs)
		if(end < seg.first)
		{
			if(star != -2e9) res.push_back({star, end});
			star = seg.first, end = seg.second;
		}
		else end = max(end, seg.second);
		
	if(star != -2e9) res.push_back({star, end});
	
	segs = res;
}

int main()
{
	cin >> n;
	
	while(n--)
	{
		int l, r;
		cin >> l >> r;
		segs.push_back({l, r});
	}
	
	merge(segs);

	cout << segs.size() << endl;
	
	return 0;
}